/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package rdfparser.controller;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URLDecoder;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import rdfparser.util.FileDirectoryHandler;

/**
 *
 * @author Amendra Shrestha
 */
public class ParserHandler extends DefaultHandler {

    /**
     * This method first decodes the filename because the provided filename
     * contains unusual character. The URL are renamed to new filename by taking
     * last part of filename and these renamed XML files are parsed by
     * respective parser.
     *
     * @param baseDir
     * @param fileDir
     * @param fileName
     * @return boolean
     */
    //public boolean parseDocument(String baseDir, String fileDir, String fileName) {
    public boolean parseDocument(String path) {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser parser;
        try {
            spf.setNamespaceAware(true);
            parser = spf.newSAXParser();
            File file = new File(path);
            parser.parse(file, this);
            return true;
        } catch (ParserConfigurationException e) {
            System.out.println("ParserConfigurationException in ParserHandler: " + e);
            return false;
        } catch (SAXException e) {
            System.out.println("SAXException in ParserHandler: " + e);
            return false;
        } catch (IOException e) {
            System.out.println("IOException in ParserHandler: " + e);
            return false;
        }
    }
}
